home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: logsizer.rexx 1.2 (25.11.97) Rolf Rotvel
- */
-
- cfgfile = 'logsizer.cfg'
-
- /*
- ** End cfg.
- */
- call addlib('rexxsupport.library', 0, -30, 0)
-
- if ~open('cfg', cfgfile, 'r') then do
- say 'Error reading '||cfgfile
- exit 10
- end
-
- nl = '0a'x
- nl2 = nl||nl
- maxstr = 65535
-
- do forever
- parse value readln('cfg') with log kb .
- if log = '' then leave
-
- info = statef(log)
- filesize = word(info, 2)
-
- select
- when ~datatype(kb, 'w') then do
- say 'New size = 'kb' kb ?!?'
- end
- when kb < 1 then do
- say 'New size = 'kb' kb ?!?'
- end
- when info = '' then do
- say 'Logfile 'log' doesn''t exist'
- end
- when filesize = 0 then do
- say 'Logfile 'log' is empty (0 bytes)'
- end
- otherwise do
- checksize = kb * 1024
-
- if filesize > checksize then do
- say 'Resizing '||log||' ('||filesize||' > '||checksize||')'
- start = filesize - checksize
-
- newlog.0 = (checksize % maxstr) + 1
-
- call open('tmp', log, 'r')
- call seek('tmp', start)
- do n = 1 to newlog.0
- newlog.n = readch('tmp', maxstr)
- end
- call close('tmp')
-
- if pos(nl2, newlog.1) > 0 then parse var newlog.1 . (nl2) newlog.1
- else parse var newlog.1 . (nl) newlog.1
-
- call open('tmp', log, 'w')
- do n = 1 to newlog.0
- call writech('tmp', newlog.n)
- end
- call close('tmp')
- end
- else say 'Skipping '||log||' ('||filesize||' <= '||checksize||')'
- end
- end
- end
-
- call close('cfg')
- exit
-